package com.csdj.music.controller;

import com.csdj.music.service.CommentService;
import com.csdj.music.vo.Comment;
import com.csdj.music.vo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: CommentController
 * @Author: XuTao
 * @Description: 评论控制器
 * @Date: 2023/3/13 15:47
 **/
@RestController
@Api(tags = "评论控制器")
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "添加评论")
    @PostMapping("/addComment")
    public RespBean add(Comment comment){
        return commentService.insert(comment);
    }
    @ApiOperation(value = "删除评论")
    @DeleteMapping("/deleteComment")
    public RespBean delete(Integer id){
        return commentService.delete(id);
    }
    @ApiOperation(value = "修改评论")
    @PutMapping("/updateComment")
    public RespBean update(Comment comment){
        return commentService.update(comment);
    }
    @ApiOperation(value = "查询所有评论")
    @GetMapping("/allComment")
    public List<Comment> allComment(){
        return commentService.allComment();
    }
    @ApiOperation(value = "根据主键id查询评论")
    @GetMapping("/selectByPrimarykey")
    public List<Comment> selectByPrimarykey(Integer id){
        return commentService.selectByPrimarykey(id);
    }
    @ApiOperation(value = "查询某个歌单下的所有评论")
    @GetMapping("/commentOfSongId")
    public List<Comment> commentOfSongId(Integer songId){
        return commentService.commentOfSongId(songId);
    }
    @ApiOperation(value = "查询某个歌手下的所有评论")
    @GetMapping("/commentOfSongListId")
    public List<Comment> commentOfSongListId(Integer songListId){ return commentService.commentOfSongListId(songListId); }
    @ApiOperation(value = "给某个评论点赞")
    @PostMapping("/like")
    public RespBean like(Comment comment){
        RespBean respBean=commentService.update(comment);
        if (respBean.getMessage().equals("修改成功")){
            return RespBean.success("200",comment);
        }
        return RespBean.error("500","点赞失败");
    }
}
